<template>
  <div class="more-mask">
    <div class="mask" @click="closeMore"></div>
    <div class="more-content" v-if="moreObj[0]">
      <div class="more-header">
        <p>{{ moreObj[0].name }}</p>
        <span @click="closeMore">x</span>
      </div>
      <div class="more-text-content">
        <p>规格</p>
        <span
          :class="{ active: currentIndex == index }"
          @click="selectMore(index)"
          v-for="(item, index) in moreObj"
          :key="index"
          >{{ item.specs_name }}</span
        >
      </div>
      <div class="more-bottom">
        <span class="more-price" v-if="moreObj.specfoods"
          >￥{{ moreObj[0].price }}</span
        >
        <span class="gou" @click="addCart">加入购物车</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    moreObj: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    addCart() {
      if (!this.moreObj[this.currentIndex].count) {
        this.$set(this.moreObj[this.currentIndex], "count", 1);
        console.log(this.moreObj[this.currentIndex].count);
      } else {
        this.moreObj[this.currentIndex].count++;
        console.log(this.moreObj[this.currentIndex].count);
      }
      this.$emit("close");
    },
    selectMore(index) {
      this.currentIndex = index;
    },
    closeMore() {
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
.more-mask {
  .mask {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background-color: rgba($color: #333, $alpha: 0.68);
    z-index: 999;
  }
  .more-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
    background-color: #fff;
    width: 6.933333rem;
    height: 5.333333rem;
    color: #333;
    border-radius: 0.333333rem;
    z-index: 1000;
    .more-header {
      padding: 0.32rem;
      box-sizing: border-box;
      width: 100%;
      position: relative;
      p {
        font-size: 0.48rem;
        text-align: center;
      }
      span {
        position: absolute;
        top: 0.133333rem;
        right: 0.426667rem;
        font-size: 0.666667rem;
        font-weight: lighter;
      }
    }
    .more-text-content {
      padding: 0.32rem;
      padding-bottom: 1.2rem;
      padding-top: 0;
      p {
        font-size: 0.373333rem;
        margin-bottom: 0.32rem;
      }
      span {
        display: inline-block;
        padding: 0.2rem 0.333333rem;
        border: 1px solid #ccc;
        border-radius: 0.133333rem;
        color: #ccc;
        margin-right: 0.32rem;
        &.active {
          border: 1px solid #3199e8;
          color: #3199e8;
        }
      }
    }
    .more-bottom {
      padding: 0 0.32rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      width: 100%;
      height: 1.066667rem;
      box-sizing: border-box;
      .more-price {
        color: #f60;
        font-size: 0.666667rem;
      }
      .gou {
        padding: 0.2rem 0.32rem;
        color: #fff;
        font-size: 0.32rem;
        background-color: #3199e8;
        border-radius: 0.2rem;
      }
    }
  }
}
</style>